//
//  UIWindow+Extension.m
//  WYCweibo
//
//  Created by 魏云超 on 15/11/22.
//  Copyright © 2015年 魏云超. All rights reserved.
//

#import "UIWindow+Extension.h"

@implementation UIWindow (Extension)
-(void)chooseRootViewController
{
    //4.判断是否是第一次使用软件,或者是升级软件
    //4.1.获取当前软件版本号,
    NSString *currentVersion = [NSBundle mainBundle].infoDictionary[@"CFBundleShortVersionString"];
    //4.2获取沙盒保存的版本号
    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
    NSString *sandboxVersion = [defaults objectForKey:@"xxoo"];
    //4.3进行比较
        UIWindow *window = [UIApplication sharedApplication].keyWindow;
        //[self.window makeKeyAndVisible];
    
    if ([currentVersion compare:sandboxVersion] == NSOrderedDescending) {
        //显示新特性
        UIStoryboard *sb = [UIStoryboard storyboardWithName:@"WYCNewFeatureController" bundle:nil];
        UIViewController *newVC = sb.instantiateInitialViewController;
        window.rootViewController = newVC;
        //保存当前软件版本号
        [defaults setObject:currentVersion forKey:@"xxoo"];
        //为了能够立刻存储 同步一下
        [defaults synchronize];
    }else{
        //显示欢迎界面
        UIStoryboard *sb = [UIStoryboard storyboardWithName:@"WYCWelcomeController" bundle:nil];
        UIViewController *wellcomeVC = sb.instantiateInitialViewController;
        window.rootViewController = wellcomeVC;
    }

}
@end
